package com.ourteam.workspace.api;

import java.io.File;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.SystemUtils;

import com.ourteam.scm.utils.VersionInfo;
import com.ourteam.workspace.domain.WorkspaceBean;

public class WorkspaceResourceFileBean {

	private File resourceFile;

	private WorkspaceBean workspaceBean;
	
	private VersionInfo versionInfo;

	public WorkspaceResourceFileBean(WorkspaceBean workspaceBean, File resourceFile) {
		super();
		this.resourceFile = resourceFile;
		this.workspaceBean = workspaceBean;
	}
	
	public String getId(){
		return workspaceBean.getId() + "@" + FilenameUtils.separatorsToUnix(resourceFile.getPath());
	}

	public File getResourceFile() {
		return resourceFile;
	}

	public String getResourcePath() {
		return FilenameUtils.separatorsToUnix( StringUtils.substringAfter(resourceFile.getPath(), workspaceBean.getWorkspacePath() + SystemUtils.FILE_SEPARATOR));
	}

	public void setResourceFile(File resourceFile) {
		this.resourceFile = resourceFile;
	}
	
	public boolean isDirectory() {
		return this.resourceFile.isDirectory();
	}

	public WorkspaceBean getWorkspaceBean() {
		return workspaceBean;
	}

	public void setWorkspaceBean(WorkspaceBean workspaceBean) {
		this.workspaceBean = workspaceBean;
	}

	public String getName() {
		return resourceFile.getName();
	}

	public VersionInfo getVersionInfo() {
		return versionInfo;
	}

	public void setVersionInfo(VersionInfo versionInfo) {
		this.versionInfo = versionInfo;
	}
	
}
